package gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @author dotekien
 *         Date: Apr 13, 2006
 *         Time: 4:14:44 PM
 */

public class NavigatorActionListener implements ActionListener {
    int type;
    Object source;

    public NavigatorActionListener(Object source, int type) {
        this.source = source;
        this.type = type;
    }

    public void actionPerformed(ActionEvent e) {
        SameComboBox cb = (SameComboBox) source;
        int index = cb.getSelectedIndex();
        if (index > -1) {
            switch (type) {
                case 0: //previous
                    if (index == 0) index = cb.getItemCount() - 1;
                    else index--;
                    cb.setSelectedIndex(index);
                    break;
                case 1: //next
                    if (index == cb.getItemCount() - 1) index = 0;
                    else index++;
                    cb.setSelectedIndex(index);
                    break;
                default:
                    break;
            }
        }

    }
}
